define(
		[ "PDAppDir/properties", "PDUtilDir/dataService", "PDAppDir/properties", "PDUtilDir/util",
			"PDUtilDir/inputSelect",
				"css!AppPathDir/spots/spotsTicketSearch/views/css/css" ],
		function(Properties, DataService, Properties, Util, inputSelect) {
			HomeApp.controller('BodyCtrl',["$scope", "$compile", '$sce', function($scope, $compile, $sce) {
				$scope.entity = DataService.getObject("spotsTicket.search.reserve" );
				$scope.cache = {
					htmls: new Array(),
					fileServer: Properties.URL_FILE_SERVER_URL,
					images: new Array(),
					typeMap: DataService.getMap("DICT.D_SPOT_TICKET_TYPE.MAP"),
					tickets: new Array()
				};
				$scope.bind = {
					ticket: new Object()
				};
				// 类型
				$.ajax({
					url : getServer() + "/flea/hclv/ticket/order/item/selectBySpotIdAndDeptId.htmls",
					async : false,
					data : {
						'spotTicketId' : $scope.entity.id
					},
					success : function(data) {
						if(data.status == 200){
							data = data.data;
							$scope.cache.images = data.qrManages;
							$scope.cache.tickets = data.ticketList;
						}
//						$scope.cache.tickets = [{
//							"type": "D_SPOT_TICKET_TYPE_ADULT",
//							"number": 100
//						},{
//							"type": "D_SPOT_TICKET_TYPE_STU",
//							"number": 100
//						},{
//							"type": "D_SPOT_TICKET_TYPE_CHILDREN",
//							"number": 100
//						},{
//							"type": "D_SPOT_TICKET_TYPE_OLD",
//							"number": 100
//						},{
//							"type": "D_SPOT_TICKET_TYPE_OTHER",
//							"number": 100
//						}];
//						<div class="col-md-4 form-horizontal" ng-repeat="item in cache.htmls">
//							<div class="form-group">
//								<label class="col-md-4 col-sm-2 control-label">{{ cache.typeMap.get(item.type) }}:</label>
//								<div class="col-md-8 col-sm-10" ng-bind-html="item.html">
//								</div>
//							</div>
//						</div>
						var eleObject = angular.element("#abcdef"), template = "", type_str = '0';
						$.each($scope.cache.tickets, function(index, row) {
							template = '<div class="col-md-4 form-horizontal">'
								+ '<div class="form-group">' 
									+ '<label class="col-md-4 col-sm-2 control-label">' + $scope.cache.typeMap.get(row.type) + ':</label>'
									+'<div class="col-md-8 col-sm-10">'
										+ '<input name="ticket_' + row.id + '" ng-model="bind.ticket.' + row.type + '_' + row.id + '" type="number" min="0" class="form-control" required>'
										+ '<span class="glyphicon glyphicon-ok form-control-feedback" ng-show="reserveSpotTicketForm.ticket_' + row.id + '.$valid"></span>'
									+'</div>'
								+ '</div></div>';
							$scope.bind.ticket[row.type + '_' + row.id] = 0;
							type_str += ' + bind.ticket.' + row.type+ '_' + row.id + ' * ' + row.price;
							eleObject.append($compile(template)($scope));
						});
                        // console.info(type_str);
						//总金额
						template = '<div class="col-md-4 form-horizontal">'
							+ '<div class="form-group">' 
								+ '<label class="col-md-4 col-sm-2 control-label">应付金额:</label>'
								+'<div class="col-md-8 col-sm-10">'
								+	'<input type="text" id="payMoney" name="payMoney" class="form-control" value="{{ ' + type_str + ' }}" disabled>'
								+'</div>'
							+ '</div></div>';
						angular.element("#sopt_ticket_search_price_sum").append($compile(template)($scope));
					}
				});
				// 支付类型
				$.ajax({
					url : getServer() + "/flea/hclv/getPayType.htmls",
					success : function(data) {
						$scope.cache.types = data.data;
						// 初始化支付类型下拉框
						inputSelect.dropCache();
						inputSelect({
							id : "payPlatformName",
							key : {
								id : "dictCode",
								name : "dictName",
								data : "data",
							},
							data : $scope.cache.types,
							simpleData : true,
							searchAble : false,
							callback : function(id, obj) {
								$scope.bind.payPlatform = id[0];
								$scope.reserveSpotTicketForm.payPlatform.$setViewValue($scope.bind.payPlatform);
							}
						});
					}
				});
				$scope.paySupport = {
					run : function() {
						var ticketObj = $scope.bind.ticket,
							tickets = new Array(),
							payinfo = $.extend({
								payMoney: angular.element('#payMoney').val()
							}, $scope.bind);
						delete payinfo["ticket"];
						
						for (var key in ticketObj) {
							tickets.push({
								ticketId: key.substring(key.lastIndexOf("_") + 1),
								ticketNum: ticketObj[key]
							});
						}
						$.ajax({
							url : getServer() + "/flea/hclv/ticket/order/item/createDeptTicketOrder.htmls",
							data : {
								model:  JSON.stringify({
									item: tickets,
									payinfo: payinfo
								})
							},
							success : function(data) {
                                if (data.status != 200) {
                                    return;
                                }
								Util.alert(data.message);
								window.top.tabs.closeTab($scope.entity.id + '_stop_ticket_search');
							}
						});
					}
				};
			}
	]);
});